<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>24.&nbsp;Email</title><link rel="stylesheet" href="css/stylesheet.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.74.0"><link rel="home" href="index.html" title="Reference Documentation"><link rel="up" href="spring-integration.html" title="Part&nbsp;VI.&nbsp;Integration"><link rel="prev" href="cci.html" title="23.&nbsp;JCA CCI"><link rel="next" href="scheduling.html" title="25.&nbsp;Task Execution and Scheduling"><!--Begin Google Analytics code--><script type="text/javascript">
			var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
			document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
		</script><script type="text/javascript">
			var pageTracker = _gat._getTracker("UA-2728886-3");
			pageTracker._setDomainName("none");
			pageTracker._setAllowLinker(true);
			pageTracker._trackPageview();
		</script><!--End Google Analytics code--></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">24.&nbsp;Email</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="cci.html">Prev</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;VI.&nbsp;Integration</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="scheduling.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="mail"></a>24.&nbsp;Email</h2></div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="mail-introduction"></a>24.1&nbsp;Introduction</h2></div></div></div><div class="sidebar"><p class="title"><b>Library dependencies</b></p><p>The following additional jars to be on the classpath of your
		application in order to be able to use the Spring Framework's email library.</p><div class="itemizedlist"><ul type="disc"><li><p>The <a class="ulink" href="http://java.sun.com/products/javamail/" target="_top">JavaMail</a> <code class="filename">mail.jar</code> library</p></li><li><p>The <a class="ulink" href="http://java.sun.com/products/javabeans/jaf/downloads/index.html" target="_top">JAF</a> <code class="filename">activation.jar</code> library</p></li></ul></div><p>All of these libraries are freely available on the web.</p></div><p>The Spring Framework provides a helpful utility library for sending
	email that shields the user from the specifics of the underlying mailing
	system and is responsible for low level resource handling on behalf of
    the client.</p><p>The <code class="literal">org.springframework.mail</code> package is the root level package
	for the Spring Framework's email support. The central interface for sending
	emails is the <code class="interfacename">MailSender</code> interface; a simple value object
	encapsulating the properties of a simple mail such as <span class="emphasis"><em>from</em></span> and
	<span class="emphasis"><em>to</em></span> (plus many others) is the <code class="classname">SimpleMailMessage</code> class.
    This package also contains a hierarchy of checked exceptions which provide
    a higher level of abstraction over the lower level mail system exceptions
    with the root exception being <code class="exceptionname">MailException</code>. Please
    refer to the JavaDocs for more information on the rich mail exception hierarchy.</p><p>The <code class="interfacename">org.springframework.mail.javamail.JavaMailSender</code>
	interface adds specialized <span class="emphasis"><em>JavaMail</em></span> features such as MIME
    message support to the <code class="interfacename">MailSender</code> interface
	(from which it inherits). <code class="interfacename">JavaMailSender</code> also provides a
	callback interface for preparation of JavaMail MIME messages, called
    <code class="interfacename">org.springframework.mail.javamail.MimeMessagePreparator</code></p></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="mail-usage"></a>24.2&nbsp;Usage</h2></div></div></div><p>Let's assume there is a business interface called <code class="interfacename">OrderManager</code>:</p><pre class="programlisting"><span class="hl-keyword">public</span> <span class="hl-keyword">interface</span> OrderManager {

    <span class="hl-keyword">void</span> placeOrder(Order order);
}</pre><p>Let us also assume that there is a requirement stating that an email message
		with an order number needs to be generated and sent to a customer placing the
		relevant order.</p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="mail-usage-simple"></a>24.2.1&nbsp;Basic <code class="interfacename">MailSender</code> and <code class="classname">SimpleMailMessage</code> usage</h3></div></div></div><pre class="programlisting"><span class="hl-keyword">import</span> org.springframework.mail.MailException;
<span class="hl-keyword">import</span> org.springframework.mail.MailSender;
<span class="hl-keyword">import</span> org.springframework.mail.SimpleMailMessage;

<span class="hl-keyword">public</span> <span class="hl-keyword">class</span> SimpleOrderManager <span class="hl-keyword">implements</span> OrderManager {

    <span class="hl-keyword">private</span> MailSender mailSender;
    <span class="hl-keyword">private</span> SimpleMailMessage templateMessage;

    <span class="hl-keyword">public</span> <span class="hl-keyword">void</span> setMailSender(MailSender mailSender) {
        <span class="hl-keyword">this</span>.mailSender = mailSender;
    }

    <span class="hl-keyword">public</span> <span class="hl-keyword">void</span> setTemplateMessage(SimpleMailMessage templateMessage) {
        <span class="hl-keyword">this</span>.templateMessage = templateMessage;
    }

    <span class="hl-keyword">public</span> <span class="hl-keyword">void</span> placeOrder(Order order) {

        <span class="hl-comment">// Do the business calculations...</span>

        <span class="hl-comment">// Call the collaborators to persist the order...</span>

        <span class="hl-comment">// Create a thread safe "copy" of the template message and customize it</span>
        SimpleMailMessage msg = <span class="hl-keyword">new</span> SimpleMailMessage(<span class="hl-keyword">this</span>.templateMessage);
        msg.setTo(order.getCustomer().getEmailAddress());
        msg.setText(
            <span class="hl-string">"Dear "</span> + order.getCustomer().getFirstName()
                + order.getCustomer().getLastName()
                + <span class="hl-string">", thank you for placing order. Your order number is "</span>
                + order.getOrderNumber());
        <span class="hl-keyword">try</span>{
            <span class="hl-keyword">this</span>.mailSender.send(msg);
        }
        <span class="hl-keyword">catch</span>(MailException ex) {
            <span class="hl-comment">// simply log it and go on...</span>
            System.err.println(ex.getMessage());            
        }
    }
}</pre><p>Find below the bean definitions for the above code:</p><pre class="programlisting">&lt;<span class="hl-tag">bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"mailSender"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"org.springframework.mail.javamail.JavaMailSenderImpl"</span>&gt;
  &lt;<span class="hl-tag">property</span> <span class="hl-attribute">name</span>=<span class="hl-value">"host"</span> <span class="hl-attribute">value</span>=<span class="hl-value">"mail.mycompany.com"</span>/&gt;
&lt;<span class="hl-tag">/bean</span>&gt;

&lt;<span class="hl-comment">!-- this is a template message that we can pre-load with default state --</span>&gt;
&lt;<span class="hl-tag">bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"templateMessage"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"org.springframework.mail.SimpleMailMessage"</span>&gt;
  &lt;<span class="hl-tag">property</span> <span class="hl-attribute">name</span>=<span class="hl-value">"from"</span> <span class="hl-attribute">value</span>=<span class="hl-value">"customerservice@mycompany.com"</span>/&gt;
  &lt;<span class="hl-tag">property</span> <span class="hl-attribute">name</span>=<span class="hl-value">"subject"</span> <span class="hl-attribute">value</span>=<span class="hl-value">"Your order"</span>/&gt;
&lt;<span class="hl-tag">/bean</span>&gt;

&lt;<span class="hl-tag">bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"orderManager"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"com.mycompany.businessapp.support.SimpleOrderManager"</span>&gt;
  &lt;<span class="hl-tag">property</span> <span class="hl-attribute">name</span>=<span class="hl-value">"mailSender"</span> <span class="hl-attribute">ref</span>=<span class="hl-value">"mailSender"</span>/&gt;
  &lt;<span class="hl-tag">property</span> <span class="hl-attribute">name</span>=<span class="hl-value">"templateMessage"</span> <span class="hl-attribute">ref</span>=<span class="hl-value">"templateMessage"</span>/&gt;
&lt;<span class="hl-tag">/bean</span>&gt;</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="mail-usage-mime"></a>24.2.2&nbsp;Using the <code class="interfacename">JavaMailSender</code> and the <code class="classname">MimeMessagePreparator</code></h3></div></div></div><p>Here is another implementation of <code class="interfacename">OrderManager</code> using
			the <code class="interfacename">MimeMessagePreparator</code> callback interface. Please note
			in this case that the <code class="literal">mailSender</code> property is of type
			<code class="interfacename">JavaMailSender</code> so that we are able to use the JavaMail
			<code class="classname">MimeMessage</code> class:</p><pre class="programlisting"><span class="hl-keyword">import</span> javax.mail.Message;
<span class="hl-keyword">import</span> javax.mail.MessagingException;
<span class="hl-keyword">import</span> javax.mail.internet.InternetAddress;
<span class="hl-keyword">import</span> javax.mail.internet.MimeMessage;

<span class="hl-keyword">import</span> javax.mail.internet.MimeMessage;
<span class="hl-keyword">import</span> org.springframework.mail.MailException;
<span class="hl-keyword">import</span> org.springframework.mail.javamail.JavaMailSender;
<span class="hl-keyword">import</span> org.springframework.mail.javamail.MimeMessagePreparator;

<span class="hl-keyword">public</span> <span class="hl-keyword">class</span> SimpleOrderManager <span class="hl-keyword">implements</span> OrderManager {

    <span class="hl-keyword">private</span> JavaMailSender mailSender;
    
    <span class="hl-keyword">public</span> <span class="hl-keyword">void</span> setMailSender(JavaMailSender mailSender) {
        <span class="hl-keyword">this</span>.mailSender = mailSender;
    }

    <span class="hl-keyword">public</span> <span class="hl-keyword">void</span> placeOrder(<span class="hl-keyword">final</span> Order order) {

        <span class="hl-comment">// Do the business calculations...</span>

        <span class="hl-comment">// Call the collaborators to persist the order...</span>
        
        MimeMessagePreparator preparator = <span class="hl-keyword">new</span> MimeMessagePreparator() {
        
            <span class="hl-keyword">public</span> <span class="hl-keyword">void</span> prepare(MimeMessage mimeMessage) <span class="hl-keyword">throws</span> Exception {
        
                mimeMessage.setRecipient(Message.RecipientType.TO, 
                        <span class="hl-keyword">new</span> InternetAddress(order.getCustomer().getEmailAddress()));
                mimeMessage.setFrom(<span class="hl-keyword">new</span> InternetAddress(<span class="hl-string">"mail@mycompany.com"</span>));
                mimeMessage.setText(
                    <span class="hl-string">"Dear "</span> + order.getCustomer().getFirstName() + <span class="hl-string">" "</span>
                        + order.getCustomer().getLastName()
                        + <span class="hl-string">", thank you for placing order. Your order number is "</span>
                        + order.getOrderNumber());
            }
        };
        <span class="hl-keyword">try</span> {
            <span class="hl-keyword">this</span>.mailSender.send(preparator);
        }
        <span class="hl-keyword">catch</span> (MailException ex) {
            <span class="hl-comment">// simply log it and go on...</span>
            System.err.println(ex.getMessage());            
        }
    }
}</pre><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.gif"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>The mail code is a crosscutting concern and could well be a candidate
				for refactoring into a <a class="link" href="aop.html" title="7.&nbsp;Aspect Oriented Programming with Spring">custom Spring AOP aspect</a>,
				which then could be executed at appropriate joinpoints on the
				<code class="interfacename">OrderManager</code> target.</p></td></tr></table></div><p>The Spring Framework's mail support ships with the standard JavaMail
			implementation. Please refer to the relevant JavaDocs for more information.</p></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="mail-javamail-mime"></a>24.3&nbsp;Using the JavaMail <code class="classname">MimeMessageHelper</code></h2></div></div></div><p>A class that comes in pretty handy when dealing with JavaMail messages is
		the <code class="classname">org.springframework.mail.javamail.MimeMessageHelper</code> class,
		which shields you from having to use the verbose JavaMail API. Using
		the <code class="classname">MimeMessageHelper</code> it is pretty easy to
		create a <code class="classname">MimeMessage</code>:</p><pre class="programlisting"><span class="hl-comment">// of course you would use DI in any real-world cases</span>
JavaMailSenderImpl sender = <span class="hl-keyword">new</span> JavaMailSenderImpl();
sender.setHost(<span class="hl-string">"mail.host.com"</span>);

MimeMessage message = sender.createMimeMessage();
MimeMessageHelper helper = <span class="hl-keyword">new</span> MimeMessageHelper(message);
helper.setTo(<span class="hl-string">"test@host.com"</span>);
helper.setText(<span class="hl-string">"Thank you for ordering!"</span>);

sender.send(message);</pre><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="mail-javamail-mime-attachments"></a>24.3.1&nbsp;Sending attachments and inline resources</h3></div></div></div><p>Multipart email messages allow for both attachments and inline resources.
			Examples of inline resources would be images or a stylesheet you want to use
			in your message, but that you don't want displayed as an attachment.</p><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="mail-javamail-mime-attachments-attachment"></a>24.3.1.1&nbsp;Attachments</h4></div></div></div><p>The following example shows you how to use the
				<code class="classname">MimeMessageHelper</code> to send an email along with a
				single JPEG image attachment.</p><pre class="programlisting">JavaMailSenderImpl sender = <span class="hl-keyword">new</span> JavaMailSenderImpl();
sender.setHost(<span class="hl-string">"mail.host.com"</span>);

MimeMessage message = sender.createMimeMessage();

<span class="hl-comment">// use the true flag to indicate you need a multipart message</span>
MimeMessageHelper helper = <span class="hl-keyword">new</span> MimeMessageHelper(message, true);
helper.setTo(<span class="hl-string">"test@host.com"</span>);

helper.setText(<span class="hl-string">"Check out this image!"</span>);

<span class="hl-comment">// let's attach the infamous windows Sample file (this time copied to c:/)</span>
FileSystemResource file = <span class="hl-keyword">new</span> FileSystemResource(<span class="hl-keyword">new</span> File(<span class="hl-string">"c:/Sample.jpg"</span>));
helper.addAttachment(<span class="hl-string">"CoolImage.jpg"</span>, file);

sender.send(message);</pre></div><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="mail-javamail-mime-attachments-inline"></a>24.3.1.2&nbsp;Inline resources</h4></div></div></div><p>The following example shows you how to use the
				<code class="classname">MimeMessageHelper</code> to send an email along with an
				inline image.</p><pre class="programlisting">JavaMailSenderImpl sender = <span class="hl-keyword">new</span> JavaMailSenderImpl();
sender.setHost(<span class="hl-string">"mail.host.com"</span>);

MimeMessage message = sender.createMimeMessage();

<span class="hl-comment">// use the true flag to indicate you need a multipart message</span>
MimeMessageHelper helper = <span class="hl-keyword">new</span> MimeMessageHelper(message, true);
helper.setTo(<span class="hl-string">"test@host.com"</span>);

<span class="hl-comment">// use the true flag to indicate the text included is HTML</span>
helper.setText(<span class="hl-string">"&lt;html&gt;&lt;body&gt;&lt;img src='cid:identifier1234'&gt;&lt;/body&gt;&lt;/html&gt;"</span>, true);

<span class="hl-comment">// let's include the infamous windows Sample file (this time copied to c:/)</span>
FileSystemResource res = <span class="hl-keyword">new</span> FileSystemResource(<span class="hl-keyword">new</span> File(<span class="hl-string">"c:/Sample.jpg"</span>));
helper.addInline(<span class="hl-string">"identifier1234"</span>, res);

sender.send(message);</pre><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Warning"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="images/warning.gif"></td><th align="left">Warning</th></tr><tr><td align="left" valign="top"><p>Inline resources are added to the mime message using the
					specified <code class="literal">Content-ID</code> (<code class="literal">identifier1234</code>
					in the above example). The order in which you are adding the text and the
					resource are <span class="bold"><strong>very</strong></span> important. Be sure to
					<span class="emphasis"><em>first add the text</em></span> and after that the resources. If
					you are doing it the other way around, it won't work!</p></td></tr></table></div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="mail-templates"></a>24.3.2&nbsp;Creating email content using a templating library</h3></div></div></div><p>The code in the previous examples explicitly created the
			content of the email message, using methods calls such as
			<code class="methodname">message.setText(..)</code>. This is fine for
			simple cases, and it is okay in the context of the aforementioned
			examples, where the intent was to show you the very basics of the API.</p><p>In your typical enterprise application though, you are not going
			to create the content of your emails using the above approach for a number
			of reasons.</p><p>
				</p><div class="itemizedlist"><ul type="disc"><li><p>Creating HTML-based email content in Java code is tedious and error prone</p></li><li><p>There is no clear separation between display logic and business logic</p></li><li><p>Changing the display structure of the email content requires writing Java code, recompiling, redeploying...</p></li></ul></div><p>
			</p><p>Typically the approach taken to address these issues is to use a template library
			such as FreeMarker or Velocity to define the display structure of email content. This leaves
			your code tasked only with creating the data that is to be rendered in the email
			template and sending the email. It is definitely a best practice for when
			the content of your emails becomes even moderately complex, and with
			the Spring Framework's support classes for FreeMarker and Velocity becomes
			quite easy to do. Find below an example of using the Velocity template library
			to create email content.</p><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="mail-templates-example"></a>24.3.2.1&nbsp;A Velocity-based example</h4></div></div></div><p>To use <a class="ulink" href="http://velocity.apache.org" target="_top">Velocity</a> to
				create your email template(s), you will need to have the Velocity libraries
				available on your classpath. You will also need to create one or more Velocity templates
				for the email content that your application needs. Find below the Velocity
				template that this example will be using. As you can see it is HTML-based,
				and since it is plain text it can be created using your favorite HTML
				or text editor.</p><pre class="programlisting"># in the com/foo/package
&lt;<span class="hl-tag">html</span>&gt;
&lt;<span class="hl-tag">body</span>&gt;
&lt;<span class="hl-tag">h3</span>&gt;Hi ${user.userName}, welcome to the Chipping Sodbury On-the-Hill message boards!&lt;<span class="hl-tag">/h3</span>&gt;

&lt;<span class="hl-tag">div</span>&gt;
   Your email address is &lt;<span class="hl-tag">a</span> <span class="hl-attribute">href</span>=<span class="hl-value">"mailto:${user.emailAddress}"</span>&gt;${user.emailAddress}&lt;<span class="hl-tag">/a</span>&gt;.
&lt;<span class="hl-tag">/div</span>&gt;
&lt;<span class="hl-tag">/body</span>&gt;

&lt;<span class="hl-tag">/html</span>&gt;</pre><p>Find below some simple code and Spring XML configuration that
				makes use of the above Velocity template to create email content and
				send email(s).</p><pre class="programlisting"><span class="hl-keyword">package</span> com.foo;

<span class="hl-keyword">import</span> org.apache.velocity.app.VelocityEngine;
<span class="hl-keyword">import</span> org.springframework.mail.javamail.JavaMailSender;
<span class="hl-keyword">import</span> org.springframework.mail.javamail.MimeMessageHelper;
<span class="hl-keyword">import</span> org.springframework.mail.javamail.MimeMessagePreparator;
<span class="hl-keyword">import</span> org.springframework.ui.velocity.VelocityEngineUtils;

<span class="hl-keyword">import</span> javax.mail.internet.MimeMessage;
<span class="hl-keyword">import</span> java.util.HashMap;
<span class="hl-keyword">import</span> java.util.Map;

<span class="hl-keyword">public</span> <span class="hl-keyword">class</span> SimpleRegistrationService <span class="hl-keyword">implements</span> RegistrationService {

   <span class="hl-keyword">private</span> JavaMailSender mailSender;
   <span class="hl-keyword">private</span> VelocityEngine velocityEngine;

   <span class="hl-keyword">public</span> <span class="hl-keyword">void</span> setMailSender(JavaMailSender mailSender) {
      <span class="hl-keyword">this</span>.mailSender = mailSender;
   }

   <span class="hl-keyword">public</span> <span class="hl-keyword">void</span> setVelocityEngine(VelocityEngine velocityEngine) {
      <span class="hl-keyword">this</span>.velocityEngine = velocityEngine;
   }

   <span class="hl-keyword">public</span> <span class="hl-keyword">void</span> register(User user) {

      <span class="hl-comment">// Do the registration logic...</span>

      sendConfirmationEmail(user);
   }

   <span class="hl-keyword">private</span> <span class="hl-keyword">void</span> sendConfirmationEmail(<span class="hl-keyword">final</span> User user) {
      MimeMessagePreparator preparator = <span class="hl-keyword">new</span> MimeMessagePreparator() {
         <span class="hl-keyword">public</span> <span class="hl-keyword">void</span> prepare(MimeMessage mimeMessage) <span class="hl-keyword">throws</span> Exception {
            MimeMessageHelper message = <span class="hl-keyword">new</span> MimeMessageHelper(mimeMessage);
            message.setTo(user.getEmailAddress());
            message.setFrom(<span class="hl-string">"webmaster@csonth.gov.uk"</span>); <span class="hl-comment">// could be parameterized...</span>
            Map model = <span class="hl-keyword">new</span> HashMap();
            model.put(<span class="hl-string">"user"</span>, user);
            String text = VelocityEngineUtils.mergeTemplateIntoString(
               velocityEngine, <span class="hl-string">"com/dns/registration-confirmation.vm"</span>, model);
            message.setText(text, true);
         }
      };
      <span class="hl-keyword">this</span>.mailSender.send(preparator);
   }
}</pre><pre class="programlisting">&lt;<span class="hl-tag">?xml version="1.0" encoding="UTF-8"?</span>&gt;
&lt;<span class="hl-tag">beans</span> <span class="hl-attribute">xmlns</span>=<span class="hl-value">"http://www.springframework.org/schema/beans"</span>
      <span class="hl-attribute">xmlns:xsi</span>=<span class="hl-value">"http://www.w3.org/2001/XMLSchema-instance"</span>
<span class="hl-attribute">xsi:schemaLocation</span>=<span class="hl-value">"http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"</span>&gt;

   &lt;<span class="hl-tag">bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"mailSender"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"org.springframework.mail.javamail.JavaMailSenderImpl"</span>&gt;
      &lt;<span class="hl-tag">property</span> <span class="hl-attribute">name</span>=<span class="hl-value">"host"</span> <span class="hl-attribute">value</span>=<span class="hl-value">"mail.csonth.gov.uk"</span>/&gt;
   &lt;<span class="hl-tag">/bean</span>&gt;

   &lt;<span class="hl-tag">bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"registrationService"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"com.foo.SimpleRegistrationService"</span>&gt;
      &lt;<span class="hl-tag">property</span> <span class="hl-attribute">name</span>=<span class="hl-value">"mailSender"</span> <span class="hl-attribute">ref</span>=<span class="hl-value">"mailSender"</span>/&gt;
      &lt;<span class="hl-tag">property</span> <span class="hl-attribute">name</span>=<span class="hl-value">"velocityEngine"</span> <span class="hl-attribute">ref</span>=<span class="hl-value">"velocityEngine"</span>/&gt;
   &lt;<span class="hl-tag">/bean</span>&gt;
   
   &lt;<span class="hl-tag">bean</span> <span class="hl-attribute">id</span>=<span class="hl-value">"velocityEngine"</span> <span class="hl-attribute">class</span>=<span class="hl-value">"org.springframework.ui.velocity.VelocityEngineFactoryBean"</span>&gt;
      &lt;<span class="hl-tag">property</span> <span class="hl-attribute">name</span>=<span class="hl-value">"velocityProperties"</span>&gt;
         &lt;<span class="hl-tag">value</span>&gt;
          resource.loader=class
          class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
         &lt;<span class="hl-tag">/value</span>&gt;
      &lt;<span class="hl-tag">/property</span>&gt;
   &lt;<span class="hl-tag">/bean</span>&gt;

&lt;<span class="hl-tag">/beans</span>&gt;</pre></div></div></div></div><!--Begin LoopFuse code--><script src="http://loopfuse.net/webrecorder/js/listen.js" type="text/javascript"></script><script type="text/javascript">
			_lf_cid = "LF_48be82fa";
			_lf_remora();
		</script><!--End LoopFuse code--><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="cci.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="spring-integration.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="scheduling.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">23.&nbsp;JCA CCI&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;25.&nbsp;Task Execution and Scheduling</td></tr></table></div><!-- Begin 2nd Google code - a mod -->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));</script>
<script type="text/javascript">
var OrgTracker = _gat._getTracker("UA-2728886-2"); OrgTracker._setDomainName("none");
OrgTracker._setAllowLinker(true);
OrgTracker._trackPageview();
</script>
 <!-- End 2nd Google code -->


<script type="text/javascript">

function detectLastFrame() {
   var thisF = this.window;
   var allF = parent.top.frames;
   return allF[allF.length - 1] == thisF; }

// Only inject the following code if this is a normal page or the last // frame of a frameset.
if (parent.top.frames.length == 0 || detectLastFrame()) {
    // Inject the SpringSource search widget too.
    document.write(unescape("%3Cscript src='http://search.springsource.org/widget/searchtool.js' type='text/javascript'%3E%3C/script%3E"));
    // Inject the Eloqua code
    document.write(unescape("%3Cscript src='/elqNow/elqCfg.js' type='text/javascript'%3E%3C/script%3E"));
    document.write(unescape("%3Cscript src='/elqNow/elqImg.js' type='text/javascript'%3E%3C/script%3E"));

}
</script>
</body>
</html>